<?PHP
    header("Content-Type: text/html; charset=utf8");
    if(!isset($_POST["submit"])){
        exit("错误执行");
    }//检测是否有submit操作 
    $name =$_POST['name'];
    // echo $name."<br>";
    $password= $_POST['password'];
    // echo $password."<br>";
    function getRealIp() {
	static $realip = null;
	if($realip !== null) {
		return $realip;
	}
 
	if(getenv('REMOTE_ADDR')) {
		$realip = getenv('REMOTE_ADDR');
	} else if(getenv('HTTP_CLIENT_IP')) {
		$realip = getenv('HTTP_CLIENT_IP');
	} else if (getenv('HTTP_X_FROWARD_FOR')) {
		$realip = getenv('HTTP_X_FROWARD_FOR');
	}
 
	return $realip;	
}
$ip=getRealIp();
// echo $ip."<br>";
include('connect.php');//链接数据库
$check = "select * from `user` where username='$name'";
$result = mysql_query($check);//执行sql
while($row = mysql_fetch_array($result))
{
    $username =  $row['username'];
    $passwd = $row['passwd'];
    $sjip2 = $row['ip2'];
}
// echo $username."<br>";
// echo $passwd."<br>";
// echo $name."<br>";
if($name==$username&&$password==$passwd)
{
        // echo $name."<br>";
        //  echo $passwd."<br>";
        include('send.php');
        if($sjip2==NULL)
        {
                $sql = "update  `user` set ip2='$ip' where username='$name'";
                // echo $sql."<br>";
                // echo $ip;
                $result = mysql_query($sql);//执行sql
                // echo $result."<br>";
                // echo "123"."<br>";
                if($result)
                {
                    echo "绑定成功";
                }
                if($result)
                {
                 sc_send("绑定成功",$name."<br>".$ip,"html","sys");   
                }
        }
        else
        {
        //修改
            echo "绑定失败，你已经绑定过了，请联系管理员";
            
             sc_send($name."绑定失败","本次绑定ip:".$ip."<br>"."已绑定ip:".$sjip2,"html","sys");  
        }
}
else
{
//修改
    echo "密码错误"."<br>";
}
mysql_close();
?>